import requests
import execjs


headers = {
    "accept": "application/json, text/javascript, */*; q=0.01",
    "accept-language": "zh-CN,zh;q=0.9",
    "cache-control": "no-cache",
    "pragma": "no-cache",
    "priority": "u=0, i",
    "referer": "https://match.yuanrenxue.cn/match/5",
    "sec-ch-ua": "\"Not)A;Brand\";v=\"8\", \"Chromium\";v=\"138\", \"Google Chrome\";v=\"138\"",
    "sec-ch-ua-mobile": "?0",
    "sec-ch-ua-platform": "\"Windows\"",
    "sec-fetch-dest": "empty",
    "sec-fetch-mode": "cors",
    "sec-fetch-site": "same-origin",
    "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36",
}
li_value = []
for i in range(5):
    with open(r'E:\Python\vscode\Crawlers\yuanrenxue\no5\task5_a.js', 'r', encoding='utf-8') as f:
        js = execjs.compile(f.read())
    sign_key = js.call('get_m')
    cookies = {
        "sessionid": "rjdrxonl8yo52grpqb01x3imz3rej6hk",
        "m": sign_key['m'],
        "RM4hZBv0dDon443M": sign_key['RM4hZBv0dDon443M']
    }
    url = "https://match.yuanrenxue.cn/api/match/5"
    params = {
        "page": i+1,
        "m": sign_key['m1'],
        "f": sign_key['f1']
    }
    response = requests.get(url, headers=headers, cookies=cookies, params=params)

    res_data = response.json()['data']
    for i in res_data:
        li_value.append(i['value'])
li_value.sort(reverse=True)
print(sum(li_value[:5]))